package com.example.templateapp.widget

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

/**
 *
 * @ProjectName:    TruckPriceChargeKotlin
 * @Package:        com.mtl.truckpricechargekotlin.widget
 * @ClassName:      ControlScrollViewPager
 * @Description:    java类作用描述
 * @Author:         yang yang
 * @CreateDate:     2020/5/9 0009 10:16
 * @UpdateUser:     更新者
 * @UpdateDate:     2020/5/9 0009 10:16
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */
class ControlScrollViewPager : ViewPager {
    var isScroll:Boolean = false

    constructor(context: Context, attributes: AttributeSet):super(context,attributes)

    constructor(context: Context):super(context)

    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        return super.dispatchTouchEvent(ev)
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        return try {
            isScroll && super.onInterceptTouchEvent(ev)
        } catch (e: IllegalArgumentException) {
            false
        }
    }

    override fun onTouchEvent(ev: MotionEvent?): Boolean {
        return !isScroll || super.onTouchEvent(ev)
    }
}